package com.qiqi.web.man;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import com.qiqi.dao.CatalogMapper;
import com.qiqi.domain.Catalog;
import com.qiqi.domain.CatalogExample;

@Controller
public class CatalogController {
	@Autowired
	private CatalogMapper catalogMapper;
	@RequestMapping("/man/catalog")
	public String  list(ModelMap model){
		CatalogExample example = new CatalogExample();
		example.createCriteria().andPidEqualTo(0);
		List<Catalog> list = catalogMapper.selectByExample(example);	
		model.put("list", list);
		return "/man/catalog/list";
	}
	@RequestMapping("/man/catalog/update/{id}")
	public String toModif(@PathVariable Integer id,ModelMap model){
		Catalog catalog = catalogMapper.selectByPrimaryKey(id);
		model.put("catalog", catalog);
		return "/man/catalog/edit";
	}
	@RequestMapping("/man/catalog/update")
	public String update(Catalog catalog,ModelMap model){
		catalogMapper.updateByPrimaryKeySelective(catalog);
		return "redirect:/man/catalog";
	}
	@RequestMapping("/man/catalog/add")
	public String add(Catalog catalog,ModelMap model){
		catalog.setPid(0);
		catalog.setLevel(0);
		catalogMapper.insertSelective(catalog);
		return "redirect:/man/catalog";
	}
	@RequestMapping("/man/catalog/toadd")
	public String toadd(){
		return "/man/catalog/edit";
	}
	@RequestMapping("/man/catalog/delete/{id}")
	public String delete(@PathVariable Integer id,ModelMap model){
		catalogMapper.deleteByPrimaryKey(id);
		return "redirect:/man/catalog";
	}
}
